<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<body>
    <div id="wrap">
        <button class="btn">删除</button>
        <ul class="list one" title="">
            <li id="first1">01</li>
            <li class="second">02</li>
            <li>03</li>
            <li name="last">04</li>
        </ul>
    </div>
</body>
<script>
    var btn = document.getElementsByClassName("btn")[0];
    var one = document.querySelector(".one");
    var first1 = document.querySelector("#first1");
    var second = document.querySelector(".second");

    //节点的修改
    //parent.replaceChild(nowNode , oldNode)用一个节点(新的节点/已存在的)替换到 另一个节点(已存在)
    btn.onclick = function(){
        var li = document.createElement("li");
        li.innerText = "我是新增的li";
        li.setAttribute("class","newLi");
        console.log(li); 
        if(second) {
            one.replaceChild(li,second);
            second = null;
        }
    }
</script>
</html>